#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time    : 2023/9/1 14:51
# @Author : 闫峰
# @File    : set_amazon_sales_ban.py

import os
import re
import time
from common.setting import ensure_path_sep
from utils.logging_tool.log_control import LogHandler
from utils.mysqlUtils.db_pool import Database
from utils.mysqlUtils.sql_server_utils import MSSQL

current_path = os.path.abspath(__file__)
current_dir = os.path.dirname(current_path)
path_list = current_path.split("\\")
dis_path = "\\".join(path_list[-2:-1])


def remove_file(info_path):
    if os.path.exists(info_path):
        os.remove(info_path)
    else:
        print(f"{info_path} 不存在")


info_path = ensure_path_sep(f"\\logs\\info-{dis_path}{time.time()}")
error_path = ensure_path_sep(f"\\logs\\\error-{dis_path}{time.time()}.log")
warning_path = ensure_path_sep(f"\\logs\\warning-{dis_path}{time.time()}.log")
remove_file(info_path)
remove_file(error_path)
remove_file(warning_path)
INFO = LogHandler(info_path, level='info')
ERROR = LogHandler(error_path, level='error')
WARNING = LogHandler(warning_path, level='warning')


class Set_amazon_sales_ban:
    db = MSSQL(ensure_path_sep("\\config\\config.yaml"), "sqlserver_db_erp_base")
    insert_db = Database(ensure_path_sep("\\config\\ceshi_mysql_config.yaml"), "log_db")

    def set_amazon_sales_ban(self):
        sql = """
        SELECT DISTINCT sku  FROM `znkdceshilog`.`set_amazon_sales_ban_copy1_copy1_copy1` WHERE text LIKE '%服务自动设置亚马逊禁售国家%';
        """
        # offset = 160073124
        # batch_size = 1000
        res1 = self.insert_db.fetch_all_tuple(sql, ())
        set1 = set(map(lambda x: x[0], res1))
        sql2 = """
        SELECT DISTINCT sku FROM `znkdceshilog`.`set_amazon_sales_ban_copy1`
        """
        res2 = self.insert_db.fetch_all_tuple(sql2, ())
        set2 = set(map(lambda x: x[0], res2))
        if set1 == set2:
            pass
        else:
            print(set1 - set2)
            print(set2 - set1)








if __name__ == '__main__':
    Set_amazon_sales_ban().set_amazon_sales_ban()
